home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: dd.chalmers.se!news.chalmers.se!sunic!pipex!hunts.x.co.uk!clive
- From: clive@sco.com (Clive D.W. Feather)
- Subject: Re: malloc(0)
- Sender: clive@x.co.uk (Clive Feather)
- Message-ID: <CLxF2A.DJ@x.co.uk>
- Date: Mon, 28 Feb 1994 08:46:58 GMT
- References: <plf.762372852@bert.cs.byu.edu>
- Organization: Santa Cruz Organization
- Lines: 22
-
- In article <plf.762372852@bert.cs.byu.edu> plf@bert.cs.byu.edu (Paul L Fagerburg) writes:
- > What's the big deal about malloc(0)? It's really considered bad
- > programming style. The ANSI definition defines malloc(0) to return
- > a NULL pointer; it's that simple. Nobody on God's green earth
- > needs to allocate 0 bytes for use; it's usally to catch that one
- > exception that really shouldn't happen anyway if you're writing
- > clean code.
-
- Gack, another idiot on the loose.
-
- The ISO and ANSI standards both defined malloc(0) to be *either* NULL
- *or* a unique pointer (and there's a separate issue as to what "unique"
- means in this context, but I won't go into it).
-
- While malloc(0) might not appear useful, being able to go realloc(ptr,0)
- is. Any code that dynamically resizes a buffer can potentially use it.
-
- --
- Clive D.W. Feather | Santa Cruz Operation | If you lie to the compiler,
- clive@sco.com | Croxley Centre | it will get its revenge.
- Phone: +44 923 816 344 | Hatters Lane, Watford | - Henry Spencer
- Fax: +44 923 210 352 | WD1 8YN, United Kingdom |
-